

import cv2
import numpy as np
import random
def plot_one_box(x, img, line_thickness=None):
    # Plots one bounding box on image img
    tl = line_thickness
    color = [random.randint(0, 255) for _ in range(4)]
    # 从左上到左下
    c1, c2 = (int(x[0]), int(x[1])), (int(x[0]), int(x[3]))
    # 从右上到右下
    c3, c4 = (int(x[2]), int(x[1])), (int(x[2]), int(x[3]))
    blk = np.zeros(img.shape, np.uint8)
    cv2.line(blk, c1, c2, color, 15, lineType=cv2.LINE_AA)
    img = cv2.addWeighted(img, 1.0, blk, 0.5, 1)
    return img
picture_path = './pic.jpg'  # 换为图片路径
picture = cv2.imread(picture_path)

xyxy = (345,167,585,373)
picture = plot_one_box(xyxy,picture,'lane',15)

cv2.imshow('picture', picture)
cv2.waitKey(0)
cv2.destroyAllWindows()